package uk.co.q3c.deplan.server.util;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarIndex {

	public static Integer toIndex(Calendar cal) {
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH);
		int day = cal.get(Calendar.DAY_OF_MONTH);
		return new Integer(year * 65536) | (month * 256) | (day);
	}

	public static Calendar toCalendar(Integer index) {
		Calendar calendar = new GregorianCalendar();
		calendar.clear();
		int year = (index.intValue() & 0xFFFF0000) / 65536;
		int month = (index.intValue() & 0xFF00) / 256;
		int day = (index.intValue() & 0xFF);
		calendar.clear();
		calendar.set(year, month, day);
		return calendar;
	}
}
